<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //迭代器 可以调取 next方法  下一步执行
        // let arr = ["张安", "李四", "王五"];

        // let iterator = arr[Symbol.iterator]();
        // let iterator = arr.entries();
        // console.log(iterator.next()); // {value: Array(2), done: false}
        // console.log(iterator.next()); // {value: Array(2), done: false}
        // console.log(iterator.next()); // {value: Array(2), done: false}
        // console.log(iterator.next()); // {value: undefined, done: true}

        // for (let [key, val] of arr.entries()) {
        //     console.log(key, val); // 0 '张安' 1 '李四' 2 '王五'
        // }

        //ES6 提供 generator 生成迭代器
        // function* myiterator() {
        //     yield "张安";
        //     yield "李四";
        //     yield "王五"
        // }

        // let iterator = myiterator();
        // console.log(iterator.next()); // {value: '张安', done: false}
        // console.log(iterator.next()); // {value: '李四', done: false}
        // console.log(iterator.next()); // {value: '王五', done: false}
        // console.log(iterator.next()); // {value: undefined, done: true}

        // for (let val of iterator) {
        //     console.log(val);
        // }
        // let newarr = [...iterator, "王小二"];
        // console.log(newarr); // ['王小二']


        //内置可迭代对象 : entries keys  values
        let obj = {
            name: "zhangsan",
            age: 20
        }
        console.log(Object.keys(obj)); // ['name', 'age']

        let arr = ["张三", "lisi", "王五"];
        let keys = arr.keys();
        console.log(keys); // Array Iterator {}
        for (let val of keys) {
            console.log(val); // 0 1 2
        }

        let values = arr.values();
        console.log(values); // Array Iterator {}
        let res=arr.entries();
        console.log(res); // Array Iterator {}
    </script>
</body>

</html>